package com.ego.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ego.common.util.PageUtil;
import com.ego.common.vo.PageVo;
import com.ego.coupon.vo.SeckillSkuRelationSearchVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ego.coupon.dao.SeckillSkuRelationDao;
import com.ego.coupon.po.SeckillSkuRelation;
import com.ego.coupon.service.SeckillSkuRelationService;

/**
 * @author KamTang
 * @program: ego
 * @description 秒杀活动商品关联对应实现类
 * @date 2022-11-13 13:17:12
 */
@Service("seckillSkuRelationService")
public class SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationDao, SeckillSkuRelation> implements SeckillSkuRelationService {
    @Override
    public PageVo<SeckillSkuRelation> search(SeckillSkuRelationSearchVo search) {
        LambdaQueryWrapper<SeckillSkuRelation> wrapper = Wrappers.<SeckillSkuRelation>lambdaQuery()
                .eq(search.getPromotionSessionId() != null,
                        SeckillSkuRelation::getPromotionSessionId,
                        search.getPromotionSessionId());
        if (StringUtils.isNotEmpty(search.getKeyword())) {
            wrapper.like(SeckillSkuRelation::getSkuId, search.getKeyword())
                    .or().like(SeckillSkuRelation::getPromotionSessionId, search.getKeyword())
                    .or().like(SeckillSkuRelation::getId, search.getKeyword());
        }

        Page<SeckillSkuRelation> page = baseMapper.selectPage(Page.of(search.getPageNum(), search.getPageSize()), wrapper);
        return PageUtil.toPage(page);
    }
}
